home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-02-19 | 9.9 KB | 308 lines | [TEXT/CWIE] |
- /*
- File: EntireContents.c
-
- Contains: The 'entire contents' property is similar to 'every item', but
- it includes every item deep inside the specified container
- (e.g. 'entire contents of startup disk' returns every item on
- the startup disk, not just the items at the root of the startup
- disk)
-
- Written by: Greg Anderson
-
- Copyright: © 1993-1995 by Apple Computer, Inc., all rights reserved.
-
- <14> 6/15/95 ga
-
- */
-
- #ifdef MWTRACEBACKTABLES
- #pragma traceback on
- #endif
-
- #include "EntireContents.h"
-
- #include "AbstractSearchSpec.h"
- #include "MarkToken.h"
-
- #include <AEObjects.h>
- #include <AEPackObject.h>
- #include <AERegistry.h>
- #include <AppleEvents.h>
-
- // #include "FinderRegistry.h"
-
- #include "Exceptions.h"
-
- //
- // For CopyMemory
- //
- #include "AbstractData.h"
-
-
- //========================================================================================
- // CLASS TEntireContents
- //========================================================================================
-
-
- #pragma segment ObjectResident
- ImplementSmallClassData(TEntireContents, clEntireContents);
-
- #pragma segment Foundation
-
- //----------------------------------------------------------------------------------------
- // TEntireContents::TEntireContents:
- //----------------------------------------------------------------------------------------
- TEntireContents::TEntireContents()
- {
- fRootItem = nil;
- } // TEntireContents::TEntireContents
-
- //----------------------------------------------------------------------------------------
- // TEntireContents::~TEntireContents:
- //----------------------------------------------------------------------------------------
- TEntireContents::~TEntireContents()
- {
- } // TEntireContents::~TEntireContents
-
- //----------------------------------------------------------------------------------------
- // TEntireContents::IEntireContents:
- //----------------------------------------------------------------------------------------
- void TEntireContents::IEntireContents(TAbstractScriptableObject* rootIcon)
- {
- fRootItem = rootIcon;
-
- TProxyToken::IProxyToken();
- } // TEntireContents::IEntireContents
-
- //----------------------------------------------------------------------------------------
- // TEntireContents::ObjectClass:
- //----------------------------------------------------------------------------------------
- DescType TEntireContents::ObjectClass(const TAETransaction& t, Boolean recordedClass /*= false*/)
- {
- if(recordedClass)
- return Inherited::ObjectClass(t, recordedClass);
- else
- return cEntireContents;
- } // TEntireContents::ObjectClass
-
- //----------------------------------------------------------------------------------------
- // TEntireContents::DerivedFromOSLClass:
- //----------------------------------------------------------------------------------------
- Boolean TEntireContents::DerivedFromOSLClass(const TAETransaction& t, DescType objectClass)
- {
- return (objectClass == cEntireContents) || (Inherited::DerivedFromOSLClass(t, objectClass));
- } // TEntireContents::DerivedFromOSLClass
-
- //----------------------------------------------------------------------------------------
- // TEntireContents::PropertyAppliesToProxy:
- //----------------------------------------------------------------------------------------
- Boolean TEntireContents::PropertyAppliesToProxy(DescType propertyName)
- {
- return ((propertyName == kAEAll) || (Inherited::PropertyAppliesToProxy(propertyName)));
- } // TEntireContents::PropertyAppliesToProxy
-
- //----------------------------------------------------------------------------------------
- // TEntireContents::ElementIterator
- //----------------------------------------------------------------------------------------
- TAbstractObjectIterator* TEntireContents::ElementIterator(const TAETransaction&)
- {
- return new TDeepIterator(fRootItem);
- } // TEntireContents::ElementIterator
-
-
- //========================================================================================
- // Class TDeepIterator
- //========================================================================================
-
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::~TDeepIterator
- //----------------------------------------------------------------------------------------
- TDeepIterator::~TDeepIterator()
- {
- this->ClearIteratorStack();
- if(fIterStack)
- delete [] fIterStack;
- fIterStack = nil;
- fStackSize = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::TopIterator
- //----------------------------------------------------------------------------------------
- TAbstractObjectIterator* TDeepIterator::TopIterator() const
- {
- TAbstractObjectIterator* iter = nil;
- if(fItersOnStack)
- {
- iter = fIterStack[fItersOnStack - 1];
- }
-
- return iter;
- }
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::PopIterator
- //----------------------------------------------------------------------------------------
- TAbstractObjectIterator* TDeepIterator::PopIterator()
- {
- TAbstractObjectIterator* iter = TopIterator();
- if(iter != nil)
- --fItersOnStack;
-
- return iter;
- }
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::PushIterator
- //----------------------------------------------------------------------------------------
- void TDeepIterator::PushIterator(TAbstractObjectIterator* iter)
- {
- if(fItersOnStack >= fStackSize)
- {
- long newStackSize = fStackSize << 1;
- if(newStackSize == 0)
- newStackSize = 8;
-
- //
- // ◊ could use ListTemplate.h here
- //
- TAbstractObjectIterator** newStack = new TAbstractObjectIterator*[newStackSize];
- if(fIterStack != nil)
- {
- CopyMemory(fIterStack, newStack, fStackSize * sizeof(Ptr)); // memcpy(newStack, fIterStack, fStackSize * sizeof(Ptr));
- delete [] fIterStack;
- }
- fIterStack = newStack;
- fStackSize = newStackSize;
- }
-
- fIterStack[fItersOnStack] = iter;
- ++fItersOnStack;
- }
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::ClearIteratorStack
- //----------------------------------------------------------------------------------------
- void TDeepIterator::ClearIteratorStack()
- {
- TAbstractObjectIterator* iter = nil;
-
- while((iter = this->PopIterator()) != nil)
- iter->Release();
- }
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::Reset
- //----------------------------------------------------------------------------------------
- void TDeepIterator::Reset(const TAETransaction& t, Boolean iterationDirection /* = kForwardIteration */)
- {
- this->ClearIteratorStack();
- fDirection = iterationDirection;
- this->PushSubtree(t, fRootItem);
- }
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::PushSubtree
- //----------------------------------------------------------------------------------------
- void TDeepIterator::PushSubtree(const TAETransaction& t, TAbstractScriptableObject* fromWhere)
- {
- TAbstractObjectIterator* iter = fromWhere->ElementIterator(t);
- while(iter != nil)
- {
- iter->Reset(t, fDirection);
- if(iter->More(t))
- {
- this->PushIterator(iter);
- TAbstractScriptableObject* current = iter->Current(t);
- iter = current->ElementIterator(t);
- current->DisposeDesignator();
- }
- else
- {
- iter->Release();
- iter = nil;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::More
- //----------------------------------------------------------------------------------------
- Boolean TDeepIterator::More(const TAETransaction& t) const
- {
- TAbstractObjectIterator* iter = TopIterator();
-
- //
- // In truth, we expect iter->More() to always be true; if it
- // isn't, then we should have removed 'iter' from the stack.
- //
- return iter ? iter->More(t) : false;
- }
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::Next
- //----------------------------------------------------------------------------------------
- void TDeepIterator::Next(const TAETransaction& t)
- {
- TAbstractObjectIterator* iter = TopIterator();
-
- if(iter != nil)
- {
- iter->Next(t);
- while(iter && (iter->More(t) == false))
- {
- this->PopIterator();
- iter = TopIterator();
- if(iter != nil)
- iter->Next(t);
- }
- if(iter != nil)
- {
- TAbstractScriptableObject* current = iter->Current(t);
- this->PushSubtree(t, current);
- current->DisposeDesignator();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::Current
- //----------------------------------------------------------------------------------------
- TAbstractScriptableObject* TDeepIterator::Current(const TAETransaction& t)
- {
- TAbstractObjectIterator* iter = TopIterator();
-
- return iter ? iter->Current(t) : nil;
- }
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::AccessBySearchSpec
- //----------------------------------------------------------------------------------------
- void TDeepIterator::AccessBySearchSpec(const TAETransaction& t, TAbstractCollector* collector, DescType desiredClass, TAbstractSearchSpec* searchSpec)
- {
- TAbstractObjectIterator* iter = fRootItem->ElementIterator(t);
- if(iter != nil)
- {
- //
- // Tell the iterator to do a deep search; results will
- // be accumulated into the collector object.
- //
- iter->SearchDeep(t, collector, desiredClass, searchSpec);
- iter->Release();
- }
- } // TDeepIterator::AccessBySearchSpec
-
- //----------------------------------------------------------------------------------------
- // TDeepIterator::SearchDeep
- //----------------------------------------------------------------------------------------
- void TDeepIterator::SearchDeep(const TAETransaction&, TAbstractCollector* /*collector*/, DescType /*desiredClass*/, TAbstractSearchSpec* /*searchSpec*/)
- {
- //
- // It should be impossible to get here
- //
- FailErr(errAEEventNotHandled);
- } // TDeepIterator::SearchDeep
-
- #pragma segment CFrontCruft
-